﻿using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;

namespace PlanesManager.Utils
{
    public class Room
    {
        public string name { get; set; }
        public double price { get; set; }
        public int category_id { get; set; }
        public string description { get; set; }
        public string image { get; set; }
    }

    public class HotelsJsonAPI
    {
        public static ICollection<Room> getRooms()
        {
            string url = "http://192.168.160.27:8080/WebApplication1/listarQuartos";
            string json = new WebClient().DownloadString(url);
            Room[] rooms = JsonConvert.DeserializeObject<Room[]>(json);
            return rooms.ToList();
        }

        public static string reservarQuarto(int idCategoria, int quantidade, string dataInicio, string datafim, string firstName,
            string lastname, string mail, string telefone)
        {
            var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://192.168.160.27:8080/WebApplication1/fazerReserva?idCategoria=" + idCategoria +
                "&quantidade=" + quantidade + "&dateInit=" + dataInicio + "&dateEnd=" + datafim + "&firstName=" + firstName +
                "&lastName=" + lastname + "&email=" + mail + "&telefone=" + telefone);
            httpWebRequest.Method = "POST";

            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
                JObject o = JObject.Parse(result);
                return o["Nr. Reserva"].ToString();

            }
        }
    }


}
